package com.hy.convenient.tool;

import org.joda.time.DateTime;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间的公用工具
 */
public class DateUitl {
    /**
     * yyyy-MM-dd HH:mm:ss
     */
    public static String fromat_01 = "yyyy-MM-dd HH:mm:ss";
    /**
     * yyyy-MM-dd HH:mm:ss
     */
    public static String fromat_01_1 = "yyyyMMddHHmmss";
    /**
     * yyyy.MM
     */
    public static String fromat_02 = "yyyy.MM";
    /**
     * yyyyMMdd
     */
    public static String fromat_03 = "yyyyMMdd";
    /**
     * yyyyMMdd
     */
    public static String fromat_03_02 = "yyyy-MM-dd";
    /**
     * yyyyMM
     */
    public static String fromat_04 = "yyyyMM";
    /**
     * yyyyMM
     */
    public static String fromat_04_02 = "yyyy-MM";

    /**
     * 00:00:00
     */
    public static String fromat_end_01 = " 00:00:00";
    /**
     * 23:59:59
     */
    public static String fromat_end_02 = " 23:59:59";


    /**
     * 昨天的月份的最小时间  yyyy-MM-dd HH:mm:ss
     */
    public static String getMonthMixTime(DateTime time) {
        return time.plusDays(-1).millisOfDay().withMinimumValue().toString(fromat_01);
    }



    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat format_02 = new SimpleDateFormat("yyyy-MM");

    public static String getDateStringFormat(Date date) {
        return DateUitl.format.format(date);
    }

    public static String getDateStringFormat_02(Date date) {
        return DateUitl.format_02.format(date);
    }

    /**
     * 获取本月天数
     *
     * @return
     */
    public static int daysOfMonth() {
        DateTime dateTime = new DateTime();
        return dateTime.dayOfMonth().getMaximumValue();
    }

    /**
     * 获取今天是周几 int
     *
     * @return
     */
    public static int daysOfWeek() {
        DateTime dateTime = new DateTime();
        return Integer.valueOf(dateTime.dayOfWeek().getAsString());
    }

    /**
     * 获取本月最大时间 格式化的字符串
     * @param selectTime
     * @param format
     * @return
     */
    public static String monthMaxDate(DateTime selectTime, String format) {
        return selectTime.dayOfMonth().withMaximumValue().millisOfDay().withMaximumValue().toString(format);
    }
    /**
     * 获取本月最下时间 格式化的字符串
     * @param selectTime
     * @param format
     * @return
     */
    public static String monthMinDate(DateTime selectTime, String format) {
        return selectTime.dayOfMonth().withMinimumValue().millisOfDay().withMinimumValue().toString(format);
    }

    /**
     * 获取当前时间的字符串
     * @return
     */
    public static String getDateString(String fromat) {
        return new DateTime().toString(fromat);
    }
}
